import {
	nextTick
} from "vue"
import {
	$store
} from "../index"
/** token name */
export const TokenKey = import.meta.env.LM_APP_TITLE_EN + 'Token'

/**  获取token */
export function getToken() {
	return uni.getStorageSync(TokenKey)
}

/** 设置token */
export function setToken(token) {
	return uni.setStorageSync(TokenKey, token)
}

/** 移除token */
export function removeToken() {
	return uni.removeStorageSync(TokenKey)
}
/** 手动执行函数是否登录拦截 */
export async function clickLogin(callback) {
	if (typeof callback !== 'function') return console.error('clickLogin  requires a function as an argument');
	const userStore = $store('user');
	if (userStore.showLogin) {
		userStore.showLogin = false
		await nextTick()
	}
	if (userStore.isLogin) {
		callback();
	} else {
		userStore.showLogin = true;
	}
}

// 默认导出
export default {
	TokenKey,
	getToken,
	setToken,
	removeToken
}